package com.zhentao.controller;

import com.zhentao.model.common.dtos.PermissionResult;
import com.zhentao.model.pojo.market.ChargeCoupon;
import com.zhentao.model.pojo.market.ChargeCouponCondition;
import com.zhentao.model.pojo.market.dto.ChargeAdminCouponDto;
import com.zhentao.model.pojo.market.dto.ChargeAdminMarker;
import com.zhentao.model.pojo.market.vo.ChargeCouponConditionVo;
import com.zhentao.service.ChargeCouponConditionService;
import com.zhentao.service.ChargeCouponService;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/admin/market")
public class AadminChargeMarkerController {
    @Resource
    ChargeCouponService chargeCouponService;
    @Resource
    ChargeCouponConditionService chargeCouponConditionService;

    /**
     * 查询所有优惠券信息
     * @param chargeAdminMarker
     * @return
     * WXQ
     */
    @PostMapping("/AdminMarketAll")
    public PermissionResult AdminMarketAll(@RequestBody ChargeAdminMarker chargeAdminMarker){
        return chargeCouponService.AdminMarketAll(chargeAdminMarker);
    }

    /**
     * 查询优惠券规则
     * @return
     * WXQ
     */
    @PostMapping("/AdminMarketConditionAll")
    public List<ChargeCouponConditionVo> AdminMarketConditionAll(){
        List<ChargeCouponCondition> list = chargeCouponConditionService.list();
        List<ChargeCouponConditionVo> chargeCouponConditionVos = new ArrayList<>();

        for (ChargeCouponCondition chargeCouponCondition : list) {
            ChargeCouponConditionVo chargeCouponConditionVo = new ChargeCouponConditionVo();
            BeanUtils.copyProperties(chargeCouponCondition,chargeCouponConditionVo);
            String a="";
            a+="满"+chargeCouponCondition.getCondition()+"元";
           if (chargeCouponCondition.getFaceValue().doubleValue()>=1){
               a+="减";
           }
           if (chargeCouponCondition.getFaceValue().doubleValue()<1){
               a+="打";
           }
           a+=chargeCouponCondition.getFaceValue().doubleValue();
           if (chargeCouponCondition.getType()>=1){
               a+="元";
           }
           if (chargeCouponCondition.getType()<1){
               a+="折";
           }
            chargeCouponConditionVo.setConditionName(a);
            chargeCouponConditionVos.add(chargeCouponConditionVo);
        }

        return chargeCouponConditionVos;
    }

    /**
     * 优惠券添加
     * WXQ
     */

    @PostMapping("/AdminMarkeyAdd")
    public PermissionResult AdminMarkeyAdd(@RequestBody ChargeAdminCouponDto condition){

        return chargeCouponService.AdminMarkeyAdd(condition);
    }

    /**
     * 优惠券修改
     * WXQ
     */
    @PostMapping("/AdminMarkeyUpdate")
    public PermissionResult AdminMarkeyUpdate(@RequestBody ChargeAdminCouponDto condition){
        return chargeCouponService.AdminMarkeyUpdate(condition);
    }
    /**
     * 优惠券删除
     * WXQ
     */
    @PostMapping("/AdminMarkeyDelete")
    public PermissionResult AdminMarkeyDelete(@RequestBody ChargeCoupon chargeCoupon){
        return chargeCouponService.AdminMarkeyDelete(chargeCoupon);
    }
}
